import img2pdf
import os
from util.console import *

# with open("test.pdf","wb") as f:
#     folder = './demo'
#     filelist = os.listdir(folder)
#     for img in sorted(filelist):
#         p(img)
#         with open(folder+"/"+img,'rb') as i:
#             f.write(img2pdf.convert(i))

# convert all files ending in .jpg inside a directory
dirname = "demo"
imgs = []
for fname in os.listdir(dirname):
    if not fname.endswith(".jpg"):
        continue
    path = os.path.join(dirname, fname)
    if os.path.isdir(path):
        continue
    imgs.append(path)
with open("name.pdf","wb") as f:
    f.write(img2pdf.convert(imgs))
